<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">房屋信息</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" label-width="120px" :inline="true" size="mini">
                    <el-form-item label="区属名称:">
                        <div style="width:170px">
                            <el-select v-model="form.qs" placeholder="请选择区属名称" clearable  @change="onSearch">
                                <el-option v-for="item in qslist" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="产别类型:">
                        <div style="width:170px">
                            <el-select v-model="form.cb" placeholder="请选择产别类型" clearable  @change="onSearch">
                                <el-option v-for="item in cblist" :key="item.code" :label="item.name" :value="item.code">
                                </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="档案编号:">
                        <div style="width:170px">
                            <el-input v-model="form.dabh" placeholder="请输入档案编号" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="房屋地址:">
                        <div style="width:170px">
                            <el-input v-model="form.fwdz" placeholder="请输入房屋地址" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="建筑面积:">
                        <div style="width:170px">
                            <el-input v-model="form.jzmj" placeholder="请输入建筑面积" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="房屋状态:">
                        <div style="width:170px">
                            <el-select v-model="form.fwzt" placeholder="请选择房屋状态" clearable style="width: 100%" @change="onSearch">
                                <el-option v-for="(item, index) in fwztlist" :key="index" :label="item.name"
                                    :value="item.code">
                                </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search" class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                        <el-button type="primary" @click="downloadlist" icon="el-icon-download"
                            class="searchcolor">导出</el-button>
                    </el-form-item>
                    <!-- <el-form-item>
                        <el-button type="primary" @click="addnew" icon="el-icon-plus" class="addcolor">添加</el-button>
                    </el-form-item> -->
                </el-form>
            </div>
            <!-- max-height="350" -->
            <el-table :data="tableData" style="width: 100%" :header-cell-style="tableHeaderColor"
                    :row-style="tablerowColor" :row-class-name="tableRowClassName" :cell-style="tablecellColor"
                border :max-height="maxHeight">
                <el-table-column prop="dabh" label="档案编号" align="center"> </el-table-column>
                <el-table-column prop="qs" label="区属" align="center" width="80"> </el-table-column>
                <el-table-column prop="fwdz" label="房屋地址" align="center"> </el-table-column>
                <el-table-column prop="cqdw" label="产权单位" align="center"> </el-table-column>
                <el-table-column prop="cb" label="产别" align="center" width="100"> </el-table-column>
                <el-table-column prop="jzmj" label="建筑面积" align="center" width="100"> </el-table-column>
                <el-table-column prop="fwzt" label="房屋状态" align="center" width="100">
                    <template slot-scope="scope">
                        <span style="font-weight: 700;color: #19BE6B;">
                            {{ scope.row.jyzt == 1 ? '出租' : '招租中' }}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="140" align="center">
                    <!-- stdwdetail stdwid: scope.row.stdwbuildinfoid-->
                    <template slot-scope="scope">
                        <router-link
                            :to="{ name: 'wtyydetail', params: { id: scope.row.id } }"
                            style="padding-right: 12px">
                            <el-button type="text" size="small">查看</el-button>
                        </router-link>
                        <!-- , stdwid: scope.row.stdwbuildinfoid -->
                        <router-link
                            :to="{ name: 'stdwedit', params: { id: scope.row.id } }"
                            style="padding-right: 12px">
                            <el-button type="text" size="small">编辑</el-button>
                        </router-link>
                        <!-- v-else -->
                        <!-- <router-link :to="{ name: 'stdwadd', params: { id: scope.row.id } }" style="padding-right: 12px"
                            >
                            <el-button type="text" size="small">编辑</el-button>
                        </router-link> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination background layout="total,prev, pager, next,jumper" :total="total"
                    :current-page.sync="current" :page-size="pageSize" @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { wtyylist, builddelete,exportwtyylist } from '@/api/index';
import global from '@/components/common/httpurl.vue'
import valueList from '@/components/common/valueList.vue'
export default {
    name: 'wtyylist',
    data() {
        return {
            rules: {},
            // 请求表头信息
            myHeaders: {
                'token': localStorage.getItem('token')
            },
            filefileList: [],//文件列表
            httpUrl: global.httpUrl,//公共地址
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                cb: '',//产别 ,
                cqdw: '',//产权单位 ,
                create_time: '',//创建时间 ,
                current: 1,//第几页 ,
                dabh: '',//档案编号 ,
                fwdz: '',//地址 ,
                id: '',//id ,
                jyzt: '',//经营状态 0：招租中 1：出租 ,
                jzmj: '',//建筑面积 ,
                pageSize: 10,//每页数量 ,
                qs: '',//区属 ,
                stdwid: this.$store.getters.company,//受托单位ID
            },
            tableData: [],
            qslist: valueList.qslist,
            cqdwlist: valueList.cqdwlist,//产权单位
            fwytlist: valueList.fwytlist,//房屋性质
            cblist: valueList.cblist,//产别
            qzlxlist: valueList.qzlxlist,//权证类型
            tdsyqlxlist: valueList.tdsyqlxlist,//土地使用权类型
            sflist: valueList.tdsyqlxlist,//是否列表
            gfdwlist: valueList.tdsyqlxlist,//管房单位
            fwztlist: valueList.fwztlist,//房屋状态列表
            maxHeight:null
        };
    },
    components: {},
    computed: {},
    methods: {
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;'
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black'
        },
        tablecellColor(){
            return "font-weight:700;color:#000000;border-color:#c0c0c0";
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row' //这是类名
            } else {
                return ''
            }
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.wtyylist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.wtyylist(this.form);
            console.log('搜索');
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.form = {
                cb: '',//产别 ,
                cqdw: '',//产权单位 ,
                create_time: '',//创建时间 ,
                current: 1,//第几页 ,
                dabh: '',//档案编号 ,
                fwdz: '',//地址 ,
                id: '',//id ,
                jyzt: '',//经营状态 0：招租中 1：出租 ,
                jzmj: '',//建筑面积 ,
                pageSize: 10,//每页数量 ,
                qs: '',//区属 ,
                stdwid: this.$store.getters.company,//受托单位ID
            };
            this.wtyylist(this.form);
            console.log('搜索');
        },
        // 添加
        addnew() {
            this.$router.push({
                name: 'addlz',
                path: '/addlz'
            });
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    builddelete(data).then((res) => {
                        if (res.code == 200) {
                            this.wtyylist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 项目列表
        wtyylist(data) {
            wtyylist(data).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 文件
        handleRemoves(file, fileList) {
            console.log(fileList)
            this.fileListshandle = fileList.map((res) => {
                return res.response.data.id;
            });
            this.fjform.fj = this.fileListshandle.toString()

        },
        // 文件删除前
        beforeRemoves(file, fileList) {
            console.log(file)
            console.log(fileList)
            return this.$confirm(`确定移除 ${file.name}？`);
        },
        // 上传成功
        handelfilesuccess(response, file, fileLists) {
            console.log(fileLists)
            console.log(file)
            this.$message.success('导入成功');
            this.fileListshandle = fileLists.map((res) => {
                console.log(res.response.data)
                return res.response.data.id;
            });
            this.fjform.fj = this.fileListshandle.toString()
        },
        // 导出
        downloadlist() {
            exportwtyylist(this.form).then(res => {
                console.log(res)
                const link = document.createElement('a');
                let blob = new Blob([res], {
                    type: 'application/vnd.ms-excel'
                });
                link.style.display = 'none';
                //设置连接
                link.href = URL.createObjectURL(blob);
                link.download = '委托运营导出文件';
                document.body.appendChild(link);
                //模拟点击事件
                link.click();
                console.log(res)
            })
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 400
        })
        console.log(this.$store.getters)
        this.wtyylist(this.form);
        console.log(valueList)
    }
};
</script>

<style scoped>
.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}

.unloadTitle {
    text-align: left;
    padding-bottom: 10px;
    box-sizing: border-box;
    color: #606266;
}</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
